package org.yanex.project.api.items;

import java.util.ArrayList;

import org.yanex.project.api.parsers.Field;
import org.yanex.project.api.parsers.ParsedItem;

public class Place extends SelfItem {
	private static final long serialVersionUID = 6439852745854118076L;
	
	private long id;
	private long categoryId;
	private double latitude = Double.NaN;
	private double longitude = Double.NaN;
	private String name = "";
	private String description = "";
	private String address = "";
	private String email = "";
	private ArrayList<String> phones = new ArrayList<String>();
	
	@Override
	public String toString() {
		String p = "";
		for (String phone : phones) {
			p+=phone+", ";
		}
		if (p.endsWith(", "))
			p=p.substring(0, p.length()-2);
		return "Place: [id="+id+"; category="+categoryId+"; name=\""+name+"\"; "+
				"description=\""+description+"\"; address=\""+address+"\"; "+
				"email=\""+email+"\"; latitude="+latitude+"; longitude="+
				longitude+"; phones=\""+p+"\"]";
	}

	public Place(ParsedItem item) {
		
		setId(item.get(Field.ID, 0l));
		setId(item.get(Field.CATEGORY, 0l));
		setName(item.get(Field.NAME, ""));
		setDescription(item.get(Field.DESCRIPTION, ""));
		setAddress(item.get(Field.ADDRRESS, ""));
		setEmail(item.get(Field.EMAIL, ""));
		
		setLatitude(item.get(Field.LATITUDE, 0d));
		setLongitude(item.get(Field.LONGITUDE, 0d));
		
		Object[] p = item.getCollection(Field.PHONE).toArray();
		for (Object o : p) {
			if (o instanceof String)
				phones.add((String)o);
		}
	}
	
	public Place(long id, long categoryId, String name) {
		this.id = id;
		this.categoryId = categoryId;
		this.name = name;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	public long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(long categoryId) {
		this.categoryId = categoryId;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public ArrayList<String> getPhones() {
		return phones;
	}
	
}
